

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Functional Component &mdash; MNMLSTC Core 1.1 documentation</title>
  

  
  

  
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  
  
    

  

  
  
    <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  

  
    <link rel="top" title="MNMLSTC Core 1.1 documentation" href="index.html"/>
        <link rel="next" title="Algorithm Component" href="algorithm.html"/>
        <link rel="prev" title="Type Traits Component" href="type-traits.html"/> 

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-nav-search">
        <a href="index.html" class="fa fa-home"> MNMLSTC Core</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        
        
            <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="usage.html">Using MNMLSTC Core</a><ul>
<li class="toctree-l2"><a class="reference internal" href="usage.html#library-layout">Library Layout</a></li>
<li class="toctree-l2"><a class="reference internal" href="usage.html#feature-addition-and-deprecation">Feature Addition and Deprecation</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="type-traits.html">Type Traits</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Functional Utilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="algorithm.html">Algorithms</a><ul>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#non-modifying-sequence-operations">Non-Modifying Sequence Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#modifying-sequence-operations">Modifying Sequence Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#partitioning-operations">Partitioning Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#sorting-operations">Sorting Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#binary-search-operations">Binary Search Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#set-operations">Set Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#heap-operations">Heap Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="algorithm.html#min-max-operations">Min/Max Operations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="iterator.html">Iterator Utilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="optional.html">Optional Types</a><ul>
<li class="toctree-l2"><a class="reference internal" href="optional.html#optional-type">Optional Type</a></li>
<li class="toctree-l2"><a class="reference internal" href="optional.html#expected-type">Expected Type</a></li>
<li class="toctree-l2"><a class="reference internal" href="optional.html#result-type">Result Type</a></li>
<li class="toctree-l2"><a class="reference internal" href="optional.html#functions">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="optional.html#specializations">Specializations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="numeric.html">Numeric Algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="variant.html">Variant Type</a><ul>
<li class="toctree-l2"><a class="reference internal" href="variant.html#specializations">Specializations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="utility.html">Uncategorized Utilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="memory.html">Memory</a><ul>
<li class="toctree-l2"><a class="reference internal" href="memory.html#polymorphic-smart-pointer">Polymorphic Smart Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#deep-copying-smart-pointer">Deep Copying Smart Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#dumbest-smart-pointer">Dumbest Smart Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#utilities">Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#comparison-operators">Comparison Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#make-functions">Make Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html#specializations">Specializations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="string.html">String Utilities</a><ul>
<li class="toctree-l2"><a class="reference internal" href="string.html#specializations">Specializations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="range.html">Range Type</a><ul>
<li class="toctree-l2"><a class="reference internal" href="range.html#specialization">Specialization</a></li>
<li class="toctree-l2"><a class="reference internal" href="range.html#answers-to-open-questions">Answers to Open Questions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="any.html">Any Type</a></li>
</ul>

        
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="index.html">MNMLSTC Core</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="index.html">Docs</a> &raquo;</li>
      
    <li>Functional Component</li>
      <li class="wy-breadcrumbs-aside">
        
          <a href="_sources/functional.txt" rel="nofollow"> View page source</a>
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            
  <div class="section" id="functional-component">
<span id="core-functional-component"></span><h1>Functional Component<a class="headerlink" href="#functional-component" title="Permalink to this headline">¶</a></h1>
<p>The functional component contains several utilities to assist with functions.
Among these are the implementation of the <em>INVOKE</em> pseudo-expression in code
form, as well as an extension of this pseudo-expression with <em>unpack</em> semantics
at both compile time and runtime.</p>
<p>Additionally, the functional component provides a <a class="reference internal" href="#function_traits:T:" title="function_traits&lt;T&gt;"><tt class="xref cpp cpp-class docutils literal"><span class="pre">function_traits&lt;T&gt;</span></tt></a>
object to discern at compile time the return type and arity of a function. The
ability to discover the types of a given function&#8217;s argument is also possible.</p>
<dl class="class">
<dt id="unpack_t">
<em class="property">class </em><tt class="descname">unpack_t</tt><a class="headerlink" href="#unpack_t" title="Permalink to this definition">¶</a></dt>
<dd><p>A sentinel class to represent that one wishes to call <a class="reference internal" href="#invoke__X" title="invoke"><tt class="xref cpp cpp-func docutils literal"><span class="pre">invoke()</span></tt></a> with
unpack semantics. An instance is available under the name <tt class="docutils literal"><span class="pre">unpack</span></tt>.</p>
</dd></dl>

<dl class="class">
<dt id="runpack_t">
<em class="property">class </em><tt class="descname">runpack_t</tt><a class="headerlink" href="#runpack_t" title="Permalink to this definition">¶</a></dt>
<dd><p>A sentinel class to represent that one wishes to call <a class="reference internal" href="#invoke__X" title="invoke"><tt class="xref cpp cpp-func docutils literal"><span class="pre">invoke()</span></tt></a> with
runtime unpack semantics. An instance is available under the name
<tt class="docutils literal"><span class="pre">runpack</span></tt>.</p>
</dd></dl>

<dl class="class">
<dt id="function_traits:T:">
<em class="property">class </em><tt class="descname">function_traits&lt;T&gt;</tt><a class="headerlink" href="#function_traits:T:" title="Permalink to this definition">¶</a></dt>
<dd><p>Function traits to discern various amounts of details for a given callable
type <em>T</em>. The traits allow one to get the <a class="reference internal" href="#function_traits:T:::arity__constexpr" title="function_traits&lt;T&gt;::arity"><tt class="xref cpp cpp-member docutils literal"><span class="pre">arity</span></tt></a> of a callable,
as well as explore the types of various argument indices.</p>
<dl class="type">
<dt id="function_traits:T:::return_type">
<em class="property">type </em><tt class="descname">return_type</tt><a class="headerlink" href="#function_traits:T:::return_type" title="Permalink to this definition">¶</a></dt>
<dd><p>The return type of a given function <em>T</em>.</p>
</dd></dl>

<dl class="type">
<dt id="function_traits:T:::pointer">
<em class="property">type </em><tt class="descname">pointer</tt><a class="headerlink" href="#function_traits:T:::pointer" title="Permalink to this definition">¶</a></dt>
<dd><p>A type alias that represents the callable as a function pointer.</p>
</dd></dl>

<dl class="member">
<dt id="function_traits:T:::arity__constexpr">
<em class="property">static</em> constexpr <tt class="descname">arity</tt><a class="headerlink" href="#function_traits:T:::arity__constexpr" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body"><tt class="docutils literal"><span class="pre">std::size_t</span></tt></td>
</tr>
</tbody>
</table>
<p>Represents the number of arguments the callable <em>T</em> takes.</p>
</dd></dl>

<dl class="type">
<dt id="function_traits:T:::argument:N:">
<em class="property">type </em><tt class="descname">argument&lt;N&gt;</tt><a class="headerlink" href="#function_traits:T:::argument:N:" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a <tt class="docutils literal"><span class="pre">std::size_t</span></tt> <em>N</em>, argument will be a type alias for the type
located at the index in its parameter list.</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="invoke__X">
auto <tt class="descname">invoke</tt><big>(</big><em>...</em><big>)</big><a class="headerlink" href="#invoke__X" title="Permalink to this definition">¶</a></dt>
<dd><p>There are 5 overloads available for this function. They are the
implementation of the <em>INVOKE</em> pseudo-expression discussed in the C++11
standard. These overloads <em>are not</em> constexpr however due to C++11 not
marking <tt class="docutils literal"><span class="pre">std::forward</span></tt> as constexpr.</p>
</dd></dl>

<dl class="function">
<dt id="invoke__X.X.X">
auto <tt class="descname">invoke</tt><big>(</big><em>unpack_t</em>, <em>Functor&amp;&amp;</em>, <em>Unpackable&amp;&amp;</em><big>)</big><a class="headerlink" href="#invoke__X.X.X" title="Permalink to this definition">¶</a></dt>
<dt id="invoke__X.X">
auto <tt class="descname">invoke</tt><big>(</big><em>unpack_t</em>, <em>Unpackable&amp;&amp;</em><big>)</big><a class="headerlink" href="#invoke__X.X" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requires:</th><td class="field-body"><em>Unpackable</em> be capable of having <tt class="docutils literal"><span class="pre">std::get&lt;N&gt;</span></tt> called on it,
and an overload for <tt class="docutils literal"><span class="pre">std::tuple_size</span></tt>.</td>
</tr>
</tbody>
</table>
<p>This version of <a class="reference internal" href="#invoke__X" title="invoke"><tt class="xref cpp cpp-func docutils literal"><span class="pre">invoke()</span></tt></a> uses compile time unpacking semantics. It
will take every member of <em>Unpackable</em> and call <tt class="docutils literal"><span class="pre">std::get&lt;N&gt;</span></tt>.
<tt class="docutils literal"><span class="pre">std::tuple_size</span></tt> is used to get the number of elements in <em>Unpackable</em>.</p>
</dd></dl>

<dl class="function">
<dt>
auto <tt class="descname">invoke</tt><big>(</big><em>runpack_t</em>, <em>Functor&amp;&amp;</em>, <em>Runpackable&amp;&amp;</em><big>)</big></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requires:</th><td class="field-body"><em>Runpackable</em> be have a member function named <em>at</em>, which returns
<tt class="docutils literal"><span class="pre">Runpackable::value_type</span></tt>, and takes a <tt class="docutils literal"><span class="pre">std::size_t</span></tt> as its
parameters.</td>
</tr>
<tr class="field-even field"><th class="field-name">Throws:</th><td class="field-body"><tt class="docutils literal"><span class="pre">std::out_of_range</span></tt></td>
</tr>
<tr class="field-odd field"><th class="field-name">Noexcept:</th><td class="field-body">false</td>
</tr>
</tbody>
</table>
<p>This version of <a class="reference internal" href="#invoke__X" title="invoke"><tt class="xref cpp cpp-func docutils literal"><span class="pre">invoke()</span></tt></a> uses runtime unpacking semantics. It will
take the arity of <em>Functor</em>, and then unpack <em>Runpackable</em> via its <tt class="docutils literal"><span class="pre">at</span></tt>
member function. As an example a <em>Functor</em> with 4 arguments, and a
<em>Runpackable</em> of type <tt class="docutils literal"><span class="pre">std::vector&lt;int&gt;</span></tt> would expand to:</p>
<div class="highlight-cpp"><div class="highlight"><pre><span class="n">core</span><span class="o">::</span><span class="n">invoke</span><span class="p">(</span>
  <span class="n">std</span><span class="o">::</span><span class="n">forward</span><span class="o">&lt;</span><span class="n">Functor</span><span class="o">&gt;</span><span class="p">(</span><span class="n">functor</span><span class="p">),</span>
  <span class="n">std</span><span class="o">::</span><span class="n">forward</span><span class="o">&lt;</span><span class="n">Runpackable</span><span class="o">&gt;</span><span class="p">(</span><span class="n">runpackable</span><span class="p">).</span><span class="n">at</span><span class="p">(</span><span class="n">N</span><span class="p">)...</span>
<span class="p">);</span>
</pre></div>
</div>
<p>As the standard containers all throw <tt class="docutils literal"><span class="pre">std::out_of_range</span></tt>, this function
should be expected to as well.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><em>ALL</em> standard containers with an <tt class="docutils literal"><span class="pre">at</span></tt> member function can be
used with this, including the associative containers, such as
<tt class="docutils literal"><span class="pre">std::map</span></tt>, and <tt class="docutils literal"><span class="pre">std::unordered_map</span></tt>. <em>However</em>, the requirement that
the <tt class="docutils literal"><span class="pre">at</span></tt> member function take a <tt class="docutils literal"><span class="pre">std::size_t</span></tt> remains.</p>
</div>
</dd></dl>

</div>


          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="algorithm.html" class="btn btn-neutral float-right" title="Algorithm Component"/>Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="type-traits.html" class="btn btn-neutral" title="Type Traits Component"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2013 - 2014, MNMLSTC.
    </p>
  </div>

  <a href="https://github.com/snide/sphinx_rtd_theme">Sphinx theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>
</footer>
        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'./',
            VERSION:'1.1',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="_static/jquery.js"></script>
      <script type="text/javascript" src="_static/underscore.js"></script>
      <script type="text/javascript" src="_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>